package com.naiterui.ehp.bs.wechat.param.custom;

import org.apache.commons.lang3.StringUtils;

import com.naiterui.ehp.bs.wechat.constants.WeChatConstant;
import com.naiterui.ehp.bs.wechat.protocol.msg.custom.CustomMsg;
import com.naiterui.ehp.bs.wechat.protocol.msg.custom.CustomText;

import lombok.Data;

/**
 * 文本消息
 *
 * @author zhoupeipei
 * @date 2019-07-05 14:50
 * @since 1.0.0
 */
@Data
public class TextMsgParam extends BaseCustomParam {
    private static final long serialVersionUID = 8435458366571675184L;
    /**
     * 消息内容
     */
    private String content;

    /**
     * @param openId
     * @param content 格式化好的消息内容,对于超链接或小程序跳转处理示例如下：
     *                <p>超链接：文本内容<a href="http://www.qq.com">点击跳连接</a></p>
     *                <p>小程序：文本内容
     *                <a href="http://www.qq.com" data-miniprogram-appid="appid" data-miniprogram-path="pages/index/index">点击跳小程序</a></p>
     */
    public TextMsgParam(String openId, String content) {
        super.setOpenId(openId);
        super.setMsgType(WeChatConstant.KefuMsgType.TEXT);
        this.content = content;
    }

    @Override
    public CustomMsg getCustomProtocol() {
        if (super.validate() && StringUtils.isNotBlank(content)) {
            CustomText customText = new CustomText(content);
            return new CustomMsg(getOpenId(), customText, getMsgType());
        }
        return null;
    }
}
